import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_model/mine/follow_user_list_model.dart';
import 'package:xvideos/hj_model/video_model.dart';
import 'package:xvideos/routers/jump_router.dart';
import 'package:xvideos/tools_base/global_store/store.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';
import 'package:xvideos/hj_utils/api_service/mine_service.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

import '../../../community_business/community_tag_page/community_tag_page.dart';

class FollowActressItem extends StatefulWidget {
  final FollowUserModel model;
  const FollowActressItem(this.model, {super.key});

  @override
  State<FollowActressItem> createState() => FollowActressItemState();
}

class FollowActressItemState extends State<FollowActressItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        pushToPersonCenter(widget.model.objcId, type: 1);
      },
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 18.w),
        padding: EdgeInsets.symmetric(horizontal: 13.w, vertical: 16.h),
        decoration: BoxDecoration(
          color: Color(0xff242424),
          borderRadius: BorderRadius.all(Radius.circular(6)),
        ),
        child: Row(
          children: [
            NetworkImageLoader(
              imageUrl: widget.model.portrait ?? "",
              width: 43,
              height: 43,
              borderRadius: 6,
            ),
            SizedBox(width: 12),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Text(
                    widget.model.name ?? "",
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                    style: TextStyle(
                      fontSize: 16,
                      color: Colors.white,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  Text(
                    "粉丝: ${widget.model.fans?.humanizeFormat}",
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 10,
                      color: Color(0xff666666),
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ],
              ),
            ),
            GestureDetector(
              onTap: () async {
                final isfollow = widget.model.hasFollow ?? false;
                final res = await MineService.postCollect(widget.model.objcId, 'actresss', !isfollow);
                if (res) {
                  widget.model.hasFollow = !isfollow;
                  setState(() {});
                }
              },
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 11.w, vertical: 5.h),
                decoration: BoxDecoration(color: Colors.white.withOpacity(.3), borderRadius: BorderRadius.circular(40)),
                child: Row(
                  children: [
                    if (widget.model.hasFollow == true) ...[
                      Image.asset(
                        'collect_red.png'.commonImgPath,
                        width: 16.w,
                        height: 16.w,
                      ),
                      7.w.sizeBoxW,
                    ],
                    Text(
                      widget.model.hasFollow == true ? '已关注' : '关注',
                      style: TextStyle(color: Colors.white, fontSize: 14),
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class FollowBloggerItem extends StatefulWidget {
  final FollowUserModel model;
  const FollowBloggerItem(this.model, {super.key});

  @override
  State<FollowBloggerItem> createState() => FollowBloggerItemState();
}

class FollowBloggerItemState extends State<FollowBloggerItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        pushToPersonCenter(widget.model.uid ?? 0);
      },
      child: Container(
        padding: EdgeInsets.only(bottom: 18, left: 16, right: 16),
        child: Row(
          children: [
            NetworkImageLoader(
              imageUrl: widget.model.portrait ?? "",
              width: 60,
              height: 60,
              borderRadius: 30,
            ),
            SizedBox(width: 12),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Text(
                    widget.model.name ?? "",
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                    style: TextStyle(
                      fontSize: 16,
                      color: Color(0xE5FFFFFF),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  6.sizeBoxH,
                   Row(
                    children: [
                      Flexible(
                        child: Text(
                          '${widget.model.totalWorks ?? 0} 作品',
                          overflow: TextOverflow.ellipsis,
                          maxLines: 1,
                          style: TextStyle(fontSize: 12, color: Color(0x8CFFFFFF), fontWeight: FontWeight.w400),
                        ),
                      ), 
                      SizedBox(width: 12),
                      Flexible(
                        child: Text(
                          '${widget.model.fans?.humanizeFormat} 粉丝',
                          overflow: TextOverflow.ellipsis,
                          maxLines: 1,
                          style: TextStyle(fontSize: 12, color: Color(0x8CFFFFFF), fontWeight: FontWeight.w400),
                        ),
                      ),
                    ],
                   )
                ],
              ),
            ),
            SizedBox(width: 12),
            Image.asset(
              'arrow_right_grey.webp'.commonImgPath,
              color: Color(0xffDCDCDC),
              width: 24,
            )
          ],
        ),
      ),
    );
  }
}

class FollowTopicItem extends StatefulWidget {
  final TagsBean model;
  const FollowTopicItem(this.model, {super.key});

  @override
  State<FollowTopicItem> createState() => _FollowTopicItemState();
}

class _FollowTopicItemState extends State<FollowTopicItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Get.to(() => CommunityTagDetailPage(), arguments: widget.model);
      },
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Expanded(
            child: Stack(
              alignment: Alignment.center,
              children: [
                NetworkImageLoader(
                  imageUrl: widget.model.coverImg ?? "",
                  width: double.infinity,
                  height: double.infinity,
                  borderRadius: 8,
                ),
                Container(
                  decoration: BoxDecoration(color: Colors.black.withOpacity(.6), borderRadius: BorderRadius.circular(8)),
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      "#${widget.model.name}",
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                      style: TextStyle(
                        fontSize: 12,
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    Text(
                      '${widget.model.videoCount.humanizeFormat}个帖子',
                      style: TextStyle(color: Color(0xffcccccc), fontSize: 10),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ],
            ),
          ),
          SizedBox(height: 12),
          GestureDetector(
            onTap: () async {
              final isCollected = widget.model.hasCollected ?? false;
              final res = await MineService.postCollect(widget.model.id, "tag", !isCollected);
              if (res) {
                widget.model.hasCollected = !isCollected;
                setState(() {});
              }
            },
            child: Container(
              width: 108,
              height: 27,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  color: Color(0xFFE1351F),
                  borderRadius: BorderRadius.circular(6)
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  // if (widget.model.hasCollected == true) ...[
                  //   Image.asset(
                  //     'collect_red.png'.commonImgPath,
                  //     width: 16.w,
                  //     height: 16.w,
                  //   ),
                  //   7.w.sizeBoxW,
                  // ],
                  Text(
                    widget.model.hasCollected == true ? '已关注' : '关注',
                    style: TextStyle(color: Colors.white, fontSize: 14),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
